package com.hiof.activities;

import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.widget.Toast;
import com.hiof.R;
import com.hiof.settings.SettingManager;
import com.hiof.utility.Utility;

/**
 * Created with IntelliJ IDEA.
 * User: manish
 * Date: 4/26/12
 * Time: 4:42 PM
 * To change this template use File | Settings | File Templates.
 */
public class Preferences extends PreferenceActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
        // Get the custom preference
        CheckBoxPreference simulationModeCheck = (CheckBoxPreference) findPreference("simulationMode");
        final EditTextPreference simulationSpeed = (EditTextPreference) findPreference("speedForSimulation");
        simulationSpeed.setText(String.valueOf(SettingManager.getInstance().getSimulationSpeed()));
        simulationSpeed.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object o) {
                int speed = Integer.parseInt(o.toString());
                SettingManager.getInstance().setSimulationSpeed(speed);
                return true;
            }
        });

        simulationModeCheck.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object o) {
                CheckBoxPreference pref = (CheckBoxPreference) preference;
                SettingManager.getInstance().setSimulation(!pref.isChecked());
                return true;
            }
        });
//        simulationSpeed.setOnPreferenceChangeListener();

    }
}
